<template>
	<view class="body">
		<view class="wrap">
			<view class="top"></view>
			<view class="content">
				<view class="title">欢迎登录果蔬商城</view>
				<input class="u-border-bottom" v-model="email" placeholder="请输入账号" />
				<input class="u-border-bottom" type="password" v-model="password" placeholder="请输入密码" />
				<button @tap="submit" :style="[inputStyle]" class="getCaptcha">登录</button>
				<view class="alternative">
					<view class="password">找回密码</view>
					<view class="issue" @click="toRegister">注册</view>
				</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	//数据库对象
	const db=uniCloud.database();
	export default {
		data() {
			return {
				email: '2747758549@qq.com', // 邮箱
				password: '123456', // 密码
			}
		},
		computed: {
			inputStyle() {
				let style = {};
				if (this.$u.test.email(this.email) && this.password) {
					style.color = "#fff";
					style.backgroundColor = this.$u.color['warning'];
				}
				return style;
			}
		},
		methods: {
			// 登录提交
			async submit() {
				if (!this.$u.test.email(this.email) || !this.password) return;
				// 获取表单数据
				const params = {
					email: this.email,
					password: this.password
				}
				// 登录
				// const res = await this.$u.api.authLogin(params)
				console.log(params)
				db.collection("user").where(
				params
				).get().then(res=>{
					console.log(res)
					// 缓冲token
					uni.setStorageSync('storage_user', res.result.data[0]);
					//跳转我的页
					 uni.switchTab({
						url: '/pages/center/index'
					});
				})
			},
			// 注册跳转
			toRegister(){
				this.$u.route({
					url: 'pages/auth/register'
				})
			},
		}
	};
</script>

<style lang="scss" scoped>
	page {
	background: url("https://gimg2.baidu.com/image_search/src=http%3A%2F%2F5b0988e595225.cdn.sohucs.com%2Fimages%2F20180806%2Fa5ae207060f14099b328a3049f8c7acc.jpeg&refer=http%3A%2F%2F5b0988e595225.cdn.sohucs.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1642998639&t=cc3f7455ca6ddf39b120ec7a387eadbb");
	// background-image: url("https://gimg2.baidu.com/image_search/src=http%3A%2F%2F5b0988e595225.cdn.sohucs.com%2Fimages%2F20180806%2Fa5ae207060f14099b328a3049f8c7acc.jpeg&refer=http%3A%2F%2F5b0988e595225.cdn.sohucs.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1642998639&t=cc3f7455ca6ddf39b120ec7a387eadbb");
	background-size: 100% 100%;
	background-repeat: no-repeat
	}
	
	// .body{
	// 	display: flex;
	// 	flex-direction: column;
	// 	justify-content: center;
	// }
	
	.u-border-bottom {
		margin-bottom: 40rpx !important;
	}

	.wrap {
		font-size: 28rpx;
		display: flex;
		justify-content: center;
		flex-direction: column;
		align-items: center;
		padding-top: 300rpx;
		.content {
			width: 600rpx;
			// margin: 300rpx auto 0;
			
			.title {
				text-align: left;
				font-size: 60rpx;
				font-weight: 500;
				margin-bottom: 100rpx;
			}

			input {
				text-align: left;
				margin-bottom: 10rpx;
				padding-bottom: 6rpx;
			}

			.tips {
				color: $u-type-info;
				margin-bottom: 60rpx;
				margin-top: 8rpx;
			}

			.getCaptcha {
				background-color: rgb(253, 243, 208);
				color: $u-tips-color;
				border: none;
				font-size: 30rpx;
				padding: 12rpx 0;

				&::after {
					border: none;
				}
			}

			.alternative {
				color: $u-tips-color;
				display: flex;
				justify-content: space-between;
				margin-top: 30rpx;
			}
		}
	}
</style>
